# frozen_string_literal: true

require "bundler/setup"
require "bundler/gem_tasks"
require "rake/testtask"

ENV["RAILS_MINITEST_PLUGIN"] = "true"

Rake::TestTask.new do |t|
  t.libs << "test"
  t.test_files = FileList["test/**/*_test.rb"].exclude("test/system/**/*", "test/dummy/**/*")
  t.verbose = true
  t.options = "--profile" if ENV["CI"]
end

Rake::TestTask.new "test:system" do |t|
  t.libs << "test"
  t.test_files = FileList["test/system/**/*_test.rb"]
  t.verbose = true
  t.options = "--profile" if ENV["CI"]
end

namespace :test do
  task isolated: :railties do
    FileList["test/**/*_test.rb"].exclude("test/system/**/*", "test/dummy/**/*").all? do |file|
      sh(Gem.ruby, "-w", "-Ilib", "-Itest", file)
    end || raise("Failures")
  end

  task :railties do
    ["action_text/engine"].all? do |railtie|
      sh(Gem.ruby, "-r", railtie, "-e", "'OK'")
    end || raise("Failures")
  end
end

task default: :test
